<template>
<div :class="`ysdq ${waitingLoading ? 'content-flow' : ''}`">
  <a-spin tip="正在加载中..." :spinning="false">
    <!-- waitingLoading -->
    <div class="ysdq-gu">
      <a-skeleton 
      :loading="waitingLoading"
      :title="false"
      :paragraph="{ rows: 8 }"
      active /> 
    </div>
    <div class="ysdq-content">
    <div :class="`detailpage-ysqd ${waitingLoading ? 'content-hide' : ''}`">
      <div v-if="waitingLoading" class="detailpage-ysqd-loading">
        <a-icon :style="{
          'fontSize':'35px',
          'color':'#999'
        }" type="loading" />
      </div>
      <template v-if="title.includes('清查表')">
        <zcczTable @loadingType="uploadingType"></zcczTable>
      </template>
      <template
        @loadingType="uploadingType"
        v-else-if="title.includes('服务项目资金统计表')"
      >
        <xmzjtjTable @loadingType="uploadingType"></xmzjtjTable>
      </template>
      <template v-else-if="title.includes('购置')">
        <zcgzsqTable @loadingType="uploadingType"></zcgzsqTable>
      </template>
      <template v-else-if="responseUrl">
        <tome-home @loadingType="uploadingType" />
      </template>
      <!-- zxtzysTable xmtzysTable -->
      <ys-table
        v-else-if="ysSids.indexOf(sId) !== -1"
        :collectData="getCollectData"
        :option="getCollectData"
        @loadingType="uploadingType"
      />
      <ComplexTable
        :mydata="getCollectData"
        @loadingType="uploadingType"
        v-else-if="
          ($attrs.formName && $attrs.formName.includes('指标调整')) ||
            (title &&
              (title.includes('追加') ||
                title.includes('指标') ||
                title.includes('调整')))
        "
      />
      <LCList v-show="!waitingLoading" :collectData="getCollectData" />
      <div class="sp-feiqi">
        <a-modal
          title="警告"
          :visible="fqDialogShow"
          :confirm-loading="fqLoading"
          @ok="sqComfirm"
          @cancel="fqDialogShow = false"
          centered
        >
          <div class="sp-conmirm-content">
            <p>
              此操作将<span class="sp-warning">永久废弃</span>该事项, 是否继续?
            </p>
          </div>
        </a-modal>
      </div>
      <div v-if="showSPBtns === '1'" class="sp-btns">
        <btns
          @item-click="bottomBtnClick"
          :items="[
            { name: '通过', id: 0 },
            { name: '驳回', id: 1 },
            { name: '废弃', id: 2 },
          ]"
          :myStyle="{
            color: '#3296FA',
          }"
        />
      </div>
    </div>
    </div>

  </a-spin>
  </div>
</template>

<script type="text/ecmascript-6">
/* eslint-disable */
const zcgzsqTable = ()=> import("@/views/DetailPage/zcgzsqTable/index.vue");
const TomeHome = () => import("@/views/components/TaoComponents/index.vue");
const ComplexTable = () => import("@/views/DetailPage/complextable/index.vue");
const xmzjtjTable = () => import("@/views/DetailPage/xmzjtjTable/index.vue");
const ysTable = () => import("@/views/DetailPage/budgetComplexTable/index.vue");
import LCList from './child/listliucheng/index.vue'
import  zcczTable from '@/views/DetailPage/zcczTable/index'
import { getTableHeader,
 findByEnterId,
 getCanBackHistoryNodes,
 findByFormGuid } from '@/api/detail/index.js'
import Btns from '../bottombtn/index.vue'
import {
    post
} from '@/server/request.ts'
export default {
    data() {
      return {
        ysSids:['zxtzysTable','xmtzysTable','xmtzysNextTable','zxtzysNextTable'],
        tableHeadr: [],
        tableData: [],
        tableHeight: 100,
        fqDialogShow:false,
        fqLoading:false,
        waitingLoading:true,
        //用于废弃接口导航
        urlMap: {  
          ZCCZTABLE: '/adminCover/status',
          COLLECTTABLE: '/adminBasic/master/status',
          ZJSBDTABLE: '/financialFund/status',
          ZJSRTABLE: '/financialContact/status',
          ZCTHTABLE: '/financialContact/status',
          FSSRTABLE: '/govNonTax/status',
          CLGZTABLE: '/vehiclePurchase/status',
          XZRYQXTABLE: '/adminAuthority/status',
          DWRYXZTABLE: '/adminAuthority/status',
          JKCPSHTABLE: '/govBuyImport/status',
          SQBGTABLE: '/adminInfo/status',
          DWXZTABLE: '/adminInfo/status',
          CWJSTABLE: '/financeState/status',
          ZJLYTABLE: '/fundResource/status',
          DWBGTABLE: '/adminInfo/status',
          RYQXSCTABLE: '/adminAuthorityDel/status',
          RYQXBGTABLE: '/adminAuthority/change/status',
          XMTZYSTABLE: '/adjustBudget/status',
          ZXTZYSTABLE: '/adjustSpecific/status',
          XMTZYSNEXTTABLE: '/adjustBudget/year/status',
          ZXTZYSNEXTTABLE: '/adjustSpecific/year/status',
          ZCGZSQTABLE: '/assetState/status',
          XMZJTJTABLE: '/govBuyFund/status',
        }
      }
    },
    props:{
      enterpriseName:{
        type: String,
        default: ''
      },
      responseUrl:{
        type: String,
        default: ''
      },
      tableId:{
        type: String,
        default: ''
      },
      showSPBtns:{
        type: String,
        default: ''
      },
      fileType:{
        type: String,
        default: ''
      },
      nodeId:{
        type: String,
        default: ''
      },
      defId:{
        type: String,
        default: ''
      },
      taskId:{
        type: String,
        default: ''
      },
      instId:{
        type: String,
        default: ''
      },
      enterpriseId:{
        type: String,
        default: ''
      },
      assigneeNames:{
        type: String,
        default: ''
      },
      formGuid:{
        type: String,
        default: ''
      },
      sId:{
        type: String,
        default: ''
      },
      title:{
        type: String,
        default: ''
      }
    },
    methods: {
      uploadingType(flag){
        this.waitingLoading = flag
      },
      headerCellClassName(){
        return 'head-col'
      },
      rowClassName(){
        return 'row-body'
      },
      bianliHead(data){
        for(let keys in data){
          data[keys].type1 = data[keys].type
          data[keys].title = data[keys].text
          if (data[keys].text === '单位名称') {
            data[keys].fixed = 'left'
          }
          delete data[keys].type
          if (data[keys].children) {
            this.bianliHead(data[keys].children)
          }
        }
      },
      refrechTableHeight(){
        const ele = this.$refs.mytable
        if (!ele) {
          return
        }
        const h = ele.offsetHeight
        const hagain = h - 85 - 20
        if (hagain) {
          this.tableHeight = hagain
        }
      },
      getTableHeader(data){
        getTableHeader(data).then(res=>{
            if (res.code === 200 && res.success) {
                this.bianliHead(res.data)
                this.tableHeadr = res.data
                this.refrechTableHeight()
            }
        })
      },
      async findByFormGuid(data){
        let resu
        await findByFormGuid(data).then(res=>{
          if (res.code === 200 && res.success) {
            resu = res.data
          }
        })

        return resu || false
      },
      getCanBackHistoryNodes(data){
        getCanBackHistoryNodes(data).then(res=>{
          sessionStorage.setItem('backToWho',res.data)
        },err=>{
          this.$message.error('获取驳回人失败')
        })
      },
      //确认废弃
      sqComfirm(){
        this.getFeiqiUrl(this.sId)
      },
      commonTablePost(data,url){
        this.fqLoading = true
        post({
          url,
          data
        }).then(res=>{
            if (res.success && res.code === 200) {
              this.fqLoading = false
              this.fqDialogShow = false
              this.$message.success('废弃成功')
              setTimeout(() => {
                this.$router.replace('/')
              }, 200);
            }else{
              this.$message.error(res.message)
            }
        },err=>{
          this.fqLoading = false
          this.$message.error('网络错误')
        })
      },
      getFeiqiUrl(sId1){
        const { urlMap } = this
        const sId = sId1.toUpperCase()
        const c = {
					'formGuid': [this.formGuid],
					'status': 0
				}
        let url = ''
        if (urlMap[sId]) {
          this.commonTablePost(c, urlMap[sId])
        }else{
          //指标调整都用这个
          this.commonTablePost(c, '/budget/reject')
        }
      },
     async bottomBtnClick(item){
        const { id } = item
        //废弃
        if (id === 2) {
          this.fqDialogShow = true
          return
        }
        if (id === 0 || id) {
          if (id === 1) {
            await this.getCanBackHistoryNodes({taskId:this.taskId})
          }
          sessionStorage.setItem('clickType',id)
          sessionStorage.setItem('enterpriseName',this.enterpriseName)
          sessionStorage.setItem('assigneeNames',this.assigneeNames)
          sessionStorage.setItem('instId',this.instId)
          sessionStorage.setItem('taskId',this.taskId)
          sessionStorage.setItem('nodeId',this.nodeId)
          sessionStorage.setItem('defId',this.defId)
          sessionStorage.setItem('formGuid',this.formGuid)
          sessionStorage.setItem('fileType', this.fileType)
          // this.getFileType(this.title)
          return this.$router.push('/sp')
        }
        return false
      }
    },
    computed:{
      getCollectData(){
        return {
          ...this.$props
        }
      }
    },
    async created() {
      // {enterpriseId: "111001"}
        // const { getTableHeader, findByFormGuid, enterpriseId, formGuid, title } = this
        // let tableId = "17"
        // if (title.includes('2021')) {
        //   tableId = "23"
        // }
        // getTableHeader({tableId,title})
        // const tableData = await findByFormGuid({formGuid,title})
        // if (tableData) {
        //   this.tableData = tableData
        // }
    },
    components:{
      Btns,
      TomeHome,
      ComplexTable,
      zcczTable,
      zcgzsqTable,
      LCList,
      xmzjtjTable,
      ysTable
    }
}
</script>

<style lang="less" scoped>
.ysdq{
  width: 100%;
  height: 100%;
}
.detailpage-ysqd {
  width: 100%;
  height: 100%;
  // padding: 12px;
  .detailpage-ysqd-loading{
    width: 100%;
    height: 100vh;
    background-color: hsla(0,0%,100%,.9);
    position: absolute;
    z-index:999;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .detailpage-ysqd-title {
    font-size: 14px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 700;
    color: #333333;
    display: grid;
  }
  .mytable {
    height: calc(100% - 30px - attr(tith));
  }
  .detailpage-ysqd-tip {
    height: 145px;
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #999999;
  }
}
.sp-btns::before {
  content: "";
  display: block;
  height: 45px;
}
.sp-warning {
  color: #eb7575;
}
/deep/.ant-modal-footer {
  // padding: 5px 10px;
  padding: 0;
  border-top: none;
  > div {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    .ant-btn {
      padding: 0;
      margin: 0;
      height: 45px;
      border-radius: 0 0 0 4px;
    }
    .ant-btn.ant-btn-primary {
      background-color: #eb7575;
      border-color: #eb7575;
      padding: 0;
      border-radius: 0 0 4px 0;
    }
  }
}
/deep/.ant-modal-footer .sp-conmirm-content {
  height: 80px;
  display: flex;
  align-items: center;
}

/deep/.ant-modal-header {
  padding: 15px 10px;
}
/deep/ .ant-skeleton-content .ant-skeleton-paragraph {
  > li{
    height: 47px;
  }
  > li{
    &:last-child{
      display: none;
    }
  }

} 
.content-hide{
  opacity: 0;
}
.content-flow{
  overflow: hidden;
}
.ysdq-gu{
  position: relative;
  top: 15px;
}
</style>
